from common import *
import math

def PrimeFacWorkerFunc(ctrlIn, ctrlOut):

    # Init
    ctrlOut((0,[]))

    while True:
        
        # Get job
        factors = []
        (w_id, (num, i, job_size)) = ctrlIn()
        sqi = int(math.pow(i,2))        
        i_max = i + job_size
        
        while (sqi <= num) and (i < i_max):
            while not num%i:
                num /= i
                factors.append(i)
            sqi += 2*i + 1
            i += 1

        ctrlOut((w_id, factors))
